package com.example.util;
//用于返回统一内容
import lombok.Data;
@Data
public class Result<T> {
   private int code;
   private String msg;
   private T data;

   public static <T> Result<T> result(int code, String msg, T data) {
       Result<T> r = new Result<T>();
       r.setCode(code);
       r.setMsg(msg);
       r.setData(data);
       return r;
   }
    // ===== 成功响应 =====
   public static <T> Result<T> success(){
       return result(200, "success", null);
   }

   public static <T> Result<T> success(T data){
       return result(200, "success", data);
   }

   public static <T> Result<T> success(String msg, T data){
       return result(200, msg, data);
   }

   public static <T> Result<T> success(String msg){
       return result(200, msg, null);
   }
    // ===== 失败响应 =====
    public static <T> Result<T> fail(String msg) {
        return result(400, msg, null);
    }

    public static <T> Result<T> fail(int code, String msg) {
        return result(code, msg, null);
    }
}

